package com.estar.assistsurvy.adapter;

import java.util.ArrayList;

import com.estar.assistsurvy.R;
import com.estar.assistsurvy.entity.Item;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyPageListviewAdapter extends BaseAdapter {

	private ArrayList<Item> list;
	private LayoutInflater inflater;
	
	public MyPageListviewAdapter(ArrayList<Item> list, Context context) {
		super();
		this.list = list;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		viewHolder holder;
		if(convertView==null){
			holder=new viewHolder();
			convertView=inflater.inflate(R.layout.listview_mypage, null);
			holder.itemIcon=(ImageView) convertView.findViewById(R.id.itemIcon);
			holder.itemName=(TextView) convertView.findViewById(R.id.itemName);
			holder.itemDetail=(ImageView) convertView.findViewById(R.id.itemDetail);
			convertView.setTag(holder);
		}else{
			holder=(viewHolder) convertView.getTag();
		}
		
		Item item=list.get(position);
		holder.itemDetail.setImageResource(R.drawable.btn_more);
		holder.itemIcon.setImageResource(item.getImg());
		holder.itemName.setText(item.getText());
		return convertView;
	}

	private class viewHolder{
		private ImageView itemIcon,itemDetail;
		private TextView itemName;
	}
}
